// Upgrade NOTE: commented out 'float4x4 _Object2World', a built-in variable
// Upgrade NOTE: commented out 'float4x4 _World2Object', a built-in variable
// Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'


Shader  "Custom/WaterBlend" {

	Properties
	 {
 _DepthTex ("Depth Map", 2D) = "white" {}
 _ColourRamp0 ("Colour ramp 0", 2D) = "white" {}
 _LightDir ("Light Direction", Vector) = (0,-1,0,0)
 _WaveHeight ("wave height", Float) = 0.5
 _WaveHeightEnd ("wave height end", Float) = 0.1
 _Blend ("_Blend", Range(0,1)) = 0
 _Speed ("Speed", Float) = 1
 _WaveLength ("WaveLength", Float) = 1
 _Amount ("Amount", Float) = 1
}

	

	SubShader
     {
  Tags { "QUEUE"="Transparent" "RenderType"="Transparent" }
  ZWrite Off
  Cull Off
  Blend One One

    LOD 100
	Pass
	{
	
	

	CGPROGRAM
	#pragma vertex vert
	#pragma fragment frag
	#include "UnityCG.cginc"
    //#define Fixed3(value)  fixed3(value, value,value)

	struct VertexInput {
    fixed4 vertex : POSITION;
	fixed2 xlv_TEXCOORD0 : TEXCOORD0;
    fixed2 xlv_TEXCOORD1 : TEXCOORD1;
    //fixed3 xlv_TEXCOORD2 : TEXCOORD2;
    //fixed3 xlv_TEXCOORD3 : TEXCOORD3;
    //fixed4 tangent : TANGENT;
    fixed3 normal : NORMAL;
    fixed4 xlv_COLOR0 : COLOR;
	//VertexInput
	};


	struct VertexOutput {
	fixed4 pos : SV_POSITION;
    UNITY_FOG_COORDS(1)
    //fixed3 xlv_COLOR0 : COLOR;
	fixed2 xlv_TEXCOORD0 : TEXCOORD0;
    fixed2 xlv_TEXCOORD1 : TEXCOORD1;
    fixed3 xlv_TEXCOORD2 : TEXCOORD2;
    fixed3 xlv_TEXCOORD3 : TEXCOORD3;
    fixed xlv_TEXCOORD4 : TEXCOORD4;
	//VertexOutput
	};

	
 
 
 // float4x4 _Object2World;
 // float4x4 _World2Object;
 float4 _DepthTex_ST;
 float _WaveHeight;
 float _WaveHeightEnd;
 float _Blend;
 float4 _LightDir;
 float _Speed;
 float _WaveLength;



 sampler2D _ColourRamp0;




	VertexOutput vert (VertexInput v)
	{
	VertexOutput o;
	//o.pos = UnityObjectToClipPos (v.vertex);
	//o.xlv_TEXCOORD0 = TRANSFORM_TEX(v.xlv_TEXCOORD0, _MainTex);
	
  float4 tmpvar_1;
  tmpvar_1 = v.vertex;
  float4 delta_2;
  float4 pointC_3;
  float4 pointB_4;
  float4 pointA_5;
  float3 tmpvar_6=float3(0,0,0);
  pointA_5.xzw = tmpvar_1.xzw;
  pointB_4.xzw = tmpvar_1.xzw;
  pointC_3.xzw = tmpvar_1.xzw;
  float tmpvar_7;
  tmpvar_7 = v.xlv_TEXCOORD1.x;
  float tmpvar_8;
  tmpvar_8 = (lerp (_WaveHeight, _WaveHeightEnd, _Blend) * v.xlv_TEXCOORD1.x);
  float tmpvar_9;
  float cse_10;
  cse_10 = (_Speed * _Time.y);
  tmpvar_9 = (sin((_WaveLength * 
    ((32.0 * v.xlv_COLOR0.x) + cse_10)
  )) * tmpvar_8);
  float tmpvar_11;
  tmpvar_11 = (sin((_WaveLength * 
    ((32.0 * v.xlv_COLOR0.y) + cse_10)
  )) * tmpvar_8);
  float tmpvar_12;
  tmpvar_12 = (sin((_WaveLength * 
    ((32.0 * v.xlv_COLOR0.z) + cse_10)
  )) * tmpvar_8);
  pointA_5.y = (v.vertex.y + tmpvar_9);
  pointB_4.y = (v.vertex.y + tmpvar_11);
  pointC_3.y = (v.vertex.y + tmpvar_12);
  float4 tmpvar_13;
  tmpvar_13.xzw = fixed3(0.0, 0.0, 0.0);
  tmpvar_13.y = tmpvar_9;
  delta_2 = tmpvar_13;
  if ((v.xlv_COLOR0.w > 0.45)) {
    float4 tmpvar_14;
    tmpvar_14.xzw = fixed3(0.0, 0.0, 0.0);
    tmpvar_14.y = tmpvar_12;
    delta_2 = tmpvar_14;
    float cse_15;
    cse_15 = (v.vertex.x + 1.0);
    pointA_5.x = cse_15;
    pointB_4.x = cse_15;
    pointB_4.z = (v.vertex.z - 1.0);
  } else {
    if ((v.xlv_COLOR0.w > 0.35)) {
      float4 tmpvar_16;
      tmpvar_16.xzw = fixed3(0.0, 0.0, 0.0);
      tmpvar_16.y = tmpvar_11;
      delta_2 = tmpvar_16;
      float cse_17;
      cse_17 = (v.vertex.z + 1.0);
      pointA_5.z = cse_17;
      pointC_3.z = cse_17;
      pointC_3.x = (v.vertex.x - 1.0);
    } else {
      if ((v.xlv_COLOR0.w > 0.25)) {
        pointB_4.z = (pointB_4.z - 1.0);
        pointC_3.x = (pointC_3.x - 1.0);
      } else {
        if ((v.xlv_COLOR0.w > 0.15)) {
          float4 tmpvar_18;
          tmpvar_18.xzw = fixed3(0.0, 0.0, 0.0);
          tmpvar_18.y = tmpvar_12;
          delta_2 = tmpvar_18;
          pointA_5.x = (pointA_5.x - 1.0);
          pointB_4.x = (pointB_4.x - 1.0);
          pointB_4.z = (pointB_4.z + 1.0);
        } else {
          if ((v.xlv_COLOR0.w > 0.05)) {
            float4 tmpvar_19;
            tmpvar_19.xzw = fixed3(0.0, 0.0, 0.0);
            tmpvar_19.y = tmpvar_11;
            delta_2 = tmpvar_19;
            pointA_5.z = (pointA_5.z - 1.0);
            pointC_3.z = (pointC_3.z - 1.0);
            pointC_3.x = (pointC_3.x + 1.0);
          } else {
            pointB_4.z = (pointB_4.z + 1.0);
            pointC_3.x = (pointC_3.x + 1.0);
          };
        };
      };
    };
  };
  float3 tmpvar_20;
  tmpvar_20 = (pointB_4.xyz - pointA_5.xyz);
  float3 tmpvar_21;
  tmpvar_21 = (pointC_3.xyz - pointA_5.xyz);
  float4 tmpvar_22;
  tmpvar_22.w = 0.0;
  tmpvar_22.xyz = normalize(((tmpvar_20.yzx * tmpvar_21.zxy) - (tmpvar_20.zxy * tmpvar_21.yzx)));
  float3 tmpvar_23;
  tmpvar_23 = normalize(mul(tmpvar_22 , unity_WorldToObject).xyz);
  tmpvar_6.y = -(dot (tmpvar_23, normalize(_LightDir).xyz));
  o.pos = UnityObjectToClipPos( (v.vertex + delta_2));
  o.xlv_TEXCOORD0 = ((v.xlv_TEXCOORD0 * _DepthTex_ST.xy) + _DepthTex_ST.zw);
  o.xlv_TEXCOORD1 = tmpvar_23;
  o.xlv_TEXCOORD2 = tmpvar_6;
  o.xlv_TEXCOORD3 = mul(unity_ObjectToWorld , (v.vertex + delta_2)).y;
  o.xlv_TEXCOORD4 = tmpvar_7;




    UNITY_TRANSFER_FOG(o,o.vertex);
   
	return o;
	}


	fixed4 frag(VertexOutput i) : SV_Target
    {
    //fixed4 tmpvar_2 = tex2D(_MainTex, i.uv);
	
  float3 ramp_1;
  half4 main_color_2;
  float2 tmpvar_3;
  tmpvar_3.x = i.xlv_TEXCOORD2.y;
  tmpvar_3.y = i.xlv_TEXCOORD0.y;
  fixed3 tmpvar_4;
  tmpvar_4 = tex2D (_ColourRamp0, tmpvar_3).xyz;
	UNITY_APPLY_FOG(i.fogCoord, tmpvar_4);
  ramp_1 = tmpvar_4;
  main_color_2.xyz = ramp_1;
  main_color_2.w = 1.0;
  return main_color_2;

	}
	ENDCG
	}
  }
}

